import java.util.*;

/**
 * Creat by TanLei
 * Description:
 * User:86183
 * Date:2022-06-16
 * Time:13:51
 */
public class TestDemo2 {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("国名女神", "冰姐姐");
        map.put("国民男神", "兵哥哥");
        System.out.println(map);
        map.put("悟净", "沙僧");
        map.put("孔明", "诸葛亮");
        map.put("孔明", "诸葛亮2");//存的是最后值key值可以一样
        map.put("guo", "诸葛亮");
        //value值可以重复
        System.out.println(map);
        //String v = map.get("国民男神");
        String v = map.getOrDefault("国民男神2", "谭磊");
        System.out.println(v);
        System.out.println(map.size());
        System.out.println(map.containsKey("国民男神"));
        System.out.println(map.containsValue("诸葛亮"));

        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        for (Map.Entry<String,String> entry:entrySet) {
            //System.out.println(entry);
            System.out.println(entry.getKey()+" "+entry.getValue());
        }
    }

    public static void main2(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("hello1");
        collection.add("hello2");
        collection.add("hello3");
        collection.add("hello4");

        System.out.println(collection);
//        Object[] integers = {1,2,3,4,5};
//        Integer[] objects = (Integer[]) integers;
        //但是单个转换没问题，这个数组底层实现有关
//        Object o = 1;
//        Integer a = (Integer) o;

        //Object[] objects = collection.toArray();
        //String[] objects1 = (String[]) collection.toArray();
        //Object[]类型不能强制转换为String[]类型
        //System.out.println(Arrays.toString(objects));

        collection.remove("hello1");
        System.out.println(collection);
        collection.clear();
        System.out.println(collection);
        System.out.println(collection.size());
        System.out.println(collection.isEmpty());
    }

    public static void main1(String[] args) {
        Collection<String> collection = new ArrayList<>();
        Collection<String> collection1 = new LinkedList<>();
        Collection<String> collection2 = new Stack<>();

        ArrayList<String> arrayList = new ArrayList<>();//顺序表
        arrayList.add("hello");
        //arrayList.add(1);

        ArrayList<Integer> arrayList1 = new ArrayList<>();//顺序表
        arrayList1.add(1);

        ArrayList<Double> arrayList2 = new ArrayList<>();

    }
}
